<style>
.fui-header:after {
	height: 0;
	border-bottom: 0 solid #D9D9D9;
}
.search-input input {
	border-radius: 1rem;
	background-color:#f2f2f2;
	border: 0 solid #ddd;
}
</style>
<div ng-show="pagedata.isshowarea ==1">
<div class="fui-page fui-page-current page-goods-list" style="background:#fff">
	<div class="fui-header" style="background:none">
		<div class="fui-header-left">
			<a ng-if="pagedata.showcity!=1" class="back" style="color:#fff" href="javascript:" ng-click="pagedata.isshowarea=0;pagedata.getdians()"></a>
			<a ng-if="pagedata.showcity==1"class="back" style="color:#fff" href="javascript:" ng-click="pagedata.showcity=0"></a>
		</div>
		<div class="title bold" style="font-size:1rem;">自提点</div>
	</div>
<div ng-show="pagedata.showcity !=1" class="fui-content" style="margin-top:2.3rem;background:#fff">
		<div class="fui-cell-group">
			<div class="fui-cell">
				<div class="fui-cell-label" ng-click="pagedata.showcity=1;pagedata.getprovince()">
					<span style="font-size:0.75rem">{{pagedata.pcd.city || '广州市'}}</span>
					<i class="icon jinyunicon icon-moreunfold"></i>
				</div>
				<div ng-click="pagedata.choose_location()" class="fui-cell-info search-input">
					<i id="searchsub" class="fa fa-search"  ng-click="pagedata.getdians()"></i>
					<input type="search" placeholder="当前位置：{{pagedata.pcd.street}}" ng-change="pagedata.getdians(true);" class="search" ng-model="pagedata.addressinfo.title"/>
				</div>
			</div>
	    </div>
		<div class="weui_cells" style="margin-top:0">
				<a class="weui_cell" href="javascript:;">
					<div class="weui_cell_bd weui_cell_primary">
						<span>{{pagedata.pcd.street ||'当前还未定位地址'}}</span>
					</div>
					<div class="weui_cell_ft red" ng-click="pagedata.uplocation(1);">
						<i class="icon icon-ditu"></i>
						重新定位
					</div>
				</a>
		</div>
		<div class="fui-cell-group" style="margin:2%">
			<div class="fui-cell" ng-repeat="item in pagedata.area_dians">
				<div class="fui-cell-icon"><i class="icon icon-map"></i></div>
				<div class="fui-cell-text">
					<div class="bold" style="width:100%;">{{item.title}}</div>
					<div style="font-size:0.55rem;color:#646464">
					{{item.address}} {{item.distance}}km
					<a href="javascript:" ng-click="pagedata.openLocation(item);" class="syscolor" style="font-size:0.55rem;"><i class="icon icon-lvyoutehui" style="font-size:0.55rem;"></i>导航</a>
					</div>
				</div>
				<div class="fui-cell-remark noremark">
					<span href="javascript:" ng-click="pagedata.setdian(item)" class="btn btn-sm btn-red" style="padding:0 0.5rem;border-radius:1rem;font-weight:400;">选择</span>
				</div>
			</div>
		</div>
		
</div>
<div class="fui-content" style="top:1.3rem;background:#fff" ng-show="pagedata.showcity ==1">
		<div class="weui_cells weui_cells_access">
				<a class="weui_cell" href="javascript:;">
					<div class="weui_cell_hd weui_cell_primary" style="padding:0.6rem 0">
						<span>当前定位/选择地区：{{pagedata.pcd.city || '广州市'}}</span>
					</div>
					<div class="weui_cell_ft" ng-click="toogle(post,'show')">
						选择县区
					</div>
				</a>
				<div class="row margin0" ng-show="post.show">
						<div class="jy-3" ng-repeat="value in pagedata.province[pagedata.pcd.province][pagedata.pcd.city]">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea(pagedata.pcd.province,pagedata.pcd.city,value);pagedata.showarea = 0;">
									<div>{{value}}</div>
									<div class="clear"></div>
							</div>
						</div>
				</div>
			</div>
			<div class="weui_cells_title">热门地区</div>
			<div class="weui_cells">
				<div class="row margin0">
					<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('广东省','深圳市','');pagedata.showarea = 0;">
									<div>深圳市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('上海市','上海市','');pagedata.showarea = 0;">
									<div>上海市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('广东省','东莞市','');pagedata.showarea = 0;">
									<div>东莞市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('北京市','北京市','');pagedata.showarea = 0;">
									<div>北京市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('江苏省','南京市','');pagedata.showarea = 0;">
									<div>南京市</div>
									<div class="clear"></div>
							</div>
						</div>
						<div class="jy-3">
							<div class="yuyue-duan" style="width:auto" ng-click="selectarea('江苏省','杭州市','');pagedata.showarea = 0;">
									<div>杭州市</div>
									<div class="clear"></div>
							</div>
						</div>
				</div>
			</div>
			<div ng-repeat="(value,data) in pagedata.province">
				<div class="weui_cells_title">{{value}}</div>
				<div class="weui_cells">
					<div class="row margin0">
						<div class="jy-3" ng-repeat="(city,data) in pagedata.province[value]">
								<div class="yuyue-duan" style="width:auto" ng-click="selectarea(value,city,'');pagedata.showarea = 0;">
										<div>{{city}}</div>
										<div class="clear"></div>
								</div>
						</div>
					</div>
				</div>
		    </div>
</div>
</div>
</div>
<script>
scope.pagedata.addressinfo={}
scope.pagedata.setdian=function(dian){
	scope.pagedata.nowdian=dian
	scope.pagedata.isshowarea =0
	scope.post_json('jy_area_dian/get_data/uparea_dianid/id='+dian.id,{},function(res){
	});
	scope.$evalAsync();
}
scope.pagedata.getdians=function(){
	scope.get('jy_area_dian/get_data/getdians/lat='+scope.pagedata.params.lat+'&lng='+scope.pagedata.params.lng,function(res){
		scope.pagedata.area_dians=res.dians
		console.log('scope.pagedata.nowdian');console.log(scope.pagedata.nowdian);
		if(!scope.pagedata.nowdian || !scope.pagedata.nowdian.id){
			scope.pagedata.nowdian=res.dians[0];
			scope.$evalAsync();
		}
	});
	scope.pagedata.pcd.lat=scope.pagedata.params.lat;
	scope.pagedata.pcd.lng=scope.pagedata.params.lng;
	scope.post_json('jy_area_dian/get_data/uppcd/',scope.pagedata.pcd,function(res){
	});
}
scope.pagedata.uplocation=function(isup){
	// 百度地图API功能
	window.scope.location(function(re){
		console.log(re);
		var lat_lng = re.lat_lng;
		scope.main.lat_lng=re.lat_lng;
		scope.main.pcd=re.addressComponents;
		scope.pagedata.params.showtype=scope.pagedata.showtype?scope.pagedata.showtype:'';
		scope.pagedata.params.lat=lat_lng.lat;
		scope.pagedata.params.lng=lat_lng.lng;
		scope.pagedata.pcd=re.addressComponents;
		scope.pagedata.pcd.street=scope.pagedata.pcd.street_recommend?scope.pagedata.pcd.street_recommend:scope.pagedata.pcd.street;
		console.log('params1');
		console.log(scope.pagedata.params);
		scope.pagedata.getdians();	
		if(isup){
			scope.message('定位成功');
			scope.$evalAsync();
		}	
	},'','',isup);
}
if(!scope.pagedata.nowdian || !scope.pagedata.nowdian.id || !scope.main.lat_lng){
	scope.pagedata.uplocation();
}else{
	if(!scope.pagedata.params.lat && scope.main.lat_lng){
		scope.pagedata.params.lat=scope.main.lat_lng.lat;
		scope.pagedata.params.lng=scope.main.lat_lng.lng;
	}
	if(!scope.pagedata.pcd && scope.main.pcd){
		scope.pagedata.pcd=scope.main.pcd;
	}
	console.log('params2');
	console.log(scope.pagedata.params);
	scope.pagedata.getdians();
}
scope.pagedata.getprovince=function(){
	scope.get('core/member.set/getprovince/',function(res){
		scope.pagedata.province=res.province
		scope.$evalAsync();
	});
}
scope.pagedata.choose_location=function(obj,field,type){
		scope.modal_func(function(res){
			if(type && res[type]){
				var ret=res[type];
			}else{
				var ret=res;
			}
			console.log(res);
			scope.pagedata.params.lat=res.lat_lng.lat;
			scope.pagedata.params.lng=res.lat_lng.lng;
			scope.pagedata.pcd.street=res.title
			scope.pagedata.getdians();
			scope.$evalAsync();
		},'','core/tools.choose_location/');
}
scope.selectarea = function(province,city,district){
	scope.$evalAsync(function(){
		scope.pagedata.pcd.province = province;
		scope.pagedata.pcd.city = city;
		scope.pagedata.pcd.district = district;
		scope.pagedata.showcity=0;
	});
}
scope.pagedata.openLocation=function(item){
	var pcdaddress= item.pcd?item.pcd.province+item.pcd.city+item.pcd.district+item.pcd.street:'';
	var post={
		'address':pcdaddress+item.address,
		'city':item.pcd?item.pcd.city:''
	}
	scope.tool.get_latlng(post,function(res){
		var lat_lng = res.location
		var address_components = res.address_components
		wx.openLocation({
			latitude: lat_lng.lat, // 纬度，浮点数，范围为90 ~ -90
			longitude: lat_lng.lng, // 经度，浮点数，范围为180 ~ -180。
			name: pcdaddress, // 位置名
			address: item.address, // 地址详情说明
			scale: 20, // 地图缩放级别,整形值,范围从1~28。默认为最大
			infoUrl: '', // 在查看位置界面底部显示的超链接,可点击跳转
			success:function(){
				//alert(1111);
			},
			fail:function(res){
				scope.message('导航异常，可能是权限问题：'+res.errMsg);
			}
		});
	});
}
</script>